/*
	A simple class for displaying file information and Prg
	Note: This is a demonstration only and not part of SWFUpload.
	Note: Some have had problems adapting this class in IE7. It may not be suitable for your application.
*/

// Constructor
// file is a SWFUpload file object
// targetID is the HTML element id attribute that the FilePrg HTML structure will be added to.
// Instantiating a new FilePrg object with an existing file will reuse/update the existing DOM elements

function FileProgress(file, targetID) {

	//'<div id="" class="prgWrapper"><div class="prgName"></div><div class="prgBarBox"><div lass="prgBar"></div></div><div class="prgCancel"></div></div>'
	this.filePrgID = file.id;

	//this.opacity = 100;
	//this.height = 0;	

	//this.filePrgWrapper = document.getElementById(this.filePrgID);

	if ($("#"+this.filePrgID).length==0) {
		$("#"+targetID).append('<div id="'+this.filePrgID+'" class="prgWrapper"><div class="prgName"></div><div class="prgStatus"></div><div class="prgBarBox"><div class="prgBar"></div></div><div class="prgCancel"></div></div>');		
		$("#"+this.filePrgID +" > " +" .prgName").append(file.name+" ("+reunit(file.size)+")");
		$("#"+this.filePrgID +" > " +" .prgCancel").append('<a  href="#">删除</a>');
	} else {
		//this.filePrgElement = this.filePrgWrapper.firstChild;
		//this.reset();
	}

	//this.height = this.filePrgWrapper.offsetHeight;
	//this.setTimer(null);
}

FileProgress.prototype.setTimer = function (timer) {
	$("#"+this.filePrgID)["FP_TIMER"] = timer;
};
FileProgress.prototype.getTimer = function (timer) {
	return $("#"+this.filePrgID)["FP_TIMER"] || null;
};

FileProgress.prototype.reset = function () {
	$("#"+this.filePrgID+" > "+".prgBarBox > .prgBar").css("width","0px");
	$("#"+prgID).show();
};

FileProgress.prototype.setProgress = function (percentage) {
	$("#"+this.filePrgID+" > "+".prgBarBox > .prgBar").css("width",percentage+"px");
};
FileProgress.prototype.setComplete = function () {
	$("#"+this.filePrgID).attr("className","prgWrapper blue");
		function _b(prgID){
		return function(){
			$("#"+prgID).hide();
		}
	$("#"+this.filePrgID +" > " +" .prgCancel").html('<a  onclick=delFile("'+this.filePrgID +'");  href="#">删除</a>');
	}
	setTimeout(_b(this.filePrgID+" > .prgStatus"), 3000);
	setTimeout(_b(this.filePrgID+" > .prgBarBox"), 3000);
	//setTimeout(_b(this.filePrgID+" > .prgBar"), 5000);
};
FileProgress.prototype.setError = function () {
	$("#"+this.filePrgID).attr("className","prgWrapper red");
	function _b(prgID){
		return function(){
			$("#"+prgID).hide();
		}
	}
	setTimeout(_b(this.filePrgID), 5000);
};
FileProgress.prototype.setCancelled = function () {
		
		function _b(prgID){
		return function(){
			$("#"+prgID).hide();
		}
	}
	setTimeout(_b(this.filePrgID), 5000);
};
FileProgress.prototype.setStatus = function (status) {
	$("#"+this.filePrgID+" > "+" .prgStatus").html(status);
};	

// Show/Hide the cancel button
FileProgress.prototype.toggleCancel = function (show, swfUploadInstance) {
	//alert($("#"+this.filePrgID+" > .prgCancel").css("display"));
	$("#"+this.filePrgID+" > .prgCancel").css("display",show?"block":"none");
	if (swfUploadInstance) {
		var fileID = this.filePrgID;
		$("#"+this.filePrgID+" > .prgCancel > a").click(function () {
			swfUploadInstance.cancelUpload(fileID);
			return false;
		});
	}
};

FileProgress.prototype.appear = function () {
	alert("appear");
};

// Fades out and clips away the FilePrg box.
FileProgress.prototype.disappear = function () {
	alert("disappear");
};